home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
C++ Files Library
/
Acere (PowerPlant, Game) 1.2
/
AcereÄ.sit
/
Acereƒ
/
Code
/
AcereApp.cp
next >
Wrap
Text File
|
1995-03-04
|
8KB
|
309 lines
// ===========================================================================
// AcereApp.cp ⌐1994 Metrowerks Inc. All rights reserved.
// ===========================================================================
//
// A simple Application class which manages text documents.
#include "AcereApp.h"
#include "CTextDoc.h"
#include "CardWell.h"
#include "CardDeck.h"
#include "WellDeck.h"
#include "WellFreeCell.h"
#include "WellStack.h"
#include <LApplication.h>
#include <LGrowZone.h>
#include "CardWindow.h"
#include <LScroller.h>
#include <LPrintout.h>
#include <LPlaceHolder.h>
#include <LDialogBox.h>
#include <LCaption.h>
#include <LStdControl.h>
#include <UReanimator.h>
#include <UMemoryMgr.h>
#include <UDrawingState.h>
#include <UPowerTools.h>
#include <URegistrar.h>
#include <UDesktop.h>
#include <Balloons.h>
AcereApp *theApp;
extern CTextDoc *theDoc;
unsigned long ourAvailRam;
const MessageT pressedOK = 2001;
// ===========================================================================
// Ñ Main Program
// ===========================================================================
void main(void)
{
// Set Debugging options
#ifdef Debug_Throw
gDebugThrow = debugAction_Alert;
#endif
#ifdef Debug_Signal
gDebugSignal = debugAction_Alert;
#endif
InitializeHeap(3); // Initialize Memory Manager
// Parameter is number of Master Pointer
// blocks to allocate
// Initialize standard Toolbox managers
UQDGlobals::InitializeToolbox(&qd);
#ifdef Debug_Signal // Check for missing MBAR, which
CheckForInitialMBAR(); // probably means that there is no
#endif // project resource file
new LGrowZone(20000); // Install a GrowZone function to catch
// low memory situations.
// Parameter is size of reserve memory
// block to allocated. The first time
// the GrowZone function is called,
// there will be at least this much
// memory left (so you'll have enough
// memory to alert the user or finish
// what you are doing).
/* if (!LDragAndDrop::DragAndDropIsPresent())
{
UDesktop::Deactivate();
::Alert(10000, nil);
UDesktop::Activate();
}
else
*/ {
theApp = new AcereApp; // Create instance of your Application
theApp->Run();
}
}
// ===========================================================================
// Ñ AcereApp Class
// ===========================================================================
// ---------------------------------------------------------------------------
// Ñ AcereApp
// ---------------------------------------------------------------------------
// Constructor
AcereApp::AcereApp()
{
short i;
theDoc = ourDoc = nil;
balloonsActive = HMGetBalloons();
aboutBox = nil;
for (i=0; i<4; i++) // load up the patterns
{
suitPats[i][0] = GetCIcon(1000+i);
suitPats[i][1] = GetCIcon(1100+i);
}
// Register classes for objects created from 'PPob' resources
URegistrar::RegisterClass('wind', (ClassCreatorFunc) CardWindow::CreateCardWindowStream);
// URegistrar::RegisterClass(LWindow::class_ID, LWindow::CreateWindowStream);
URegistrar::RegisterClass(LStdButton::class_ID, LStdButton::CreateStdButtonStream);
// URegistrar::RegisterClass(LButton::class_ID, LButton::CreateButtonStream);
URegistrar::RegisterClass(LDialogBox::class_ID, LDialogBox::CreateDialogBoxStream);
URegistrar::RegisterClass(LCaption::class_ID, LCaption::CreateCaptionStream);
URegistrar::RegisterClass('scrl', (ClassCreatorFunc) LScroller::CreateScrollerStream);
// URegistrar::RegisterClass('Dtxt', (ClassCreatorFunc) CDirtyText::CreateDirtyTextStream);
URegistrar::RegisterClass('plac', (ClassCreatorFunc) LPlaceHolder::CreatePlaceHolderStream);
URegistrar::RegisterClass('prto', (ClassCreatorFunc) LPrintout::CreatePrintoutStream);
URegistrar::RegisterClass('view', (ClassCreatorFunc) CardWell::CreateCardWell);
URegistrar::RegisterClass('CWwl', (ClassCreatorFunc) WellFreeCell::CreateWellFreeCell);
URegistrar::RegisterClass('CWdk', (ClassCreatorFunc) WellStack::CreateWellStack);
URegistrar::RegisterClass('CWst', (ClassCreatorFunc) WellDeck::CreateWellDeck);
}
// ---------------------------------------------------------------------------
// Ñ ~AcereApp
// ---------------------------------------------------------------------------
// Destructor
AcereApp::~AcereApp()
{
// +++ Add code here to cleanup (if necessary) before quitting
if (aboutBox != nil)
delete aboutBox;
}
void AcereApp::StartUp()
{
theDoc = nil;
ourDoc = (CTextDoc *)MakeNewDocument();
}
void AcereApp::ProcessNextEvent()
{
balloonsActive = HMGetBalloons();
ourAvailRam = MaxBlock();
LDocApplication::ProcessNextEvent();
}
Boolean AcereApp::AllowSubRemoval(LCommander *inSub)
{
if (inSub == aboutBox)
aboutBox = nil;
return (true);
}
// ---------------------------------------------------------------------------
// Ñ ObeyCommand
// ---------------------------------------------------------------------------
// Respond to commands
Boolean AcereApp::ObeyCommand(
CommandT inCommand,
void *ioParam)
{
Boolean cmdHandled = true;
switch (inCommand) {
// +++ Add cases here for the commands you handle
// Remember to add same cases to FindCommandStatus below
// to enable/disable the menu items for the commands
cmdAbout:
cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
break;
default:
cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
break;
}
return cmdHandled;
}
// ---------------------------------------------------------------------------
// Ñ FindCommandStatus
// ---------------------------------------------------------------------------
// Pass back status of a (menu) command
void
AcereApp::FindCommandStatus(
CommandT inCommand,
Boolean &outEnabled,
Boolean &outUsesMark,
Char16 &outMark,
Str255 outName)
{
outUsesMark = false;
switch (inCommand) {
// +++ Add cases here for the commands you handle
default:
LDocApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
outMark, outName);
break;
}
}
void AcereApp::ShowAboutBox()
{
// aboutBox = LWindow::CreateWindow(1000, this);
aboutBox = (LDialogBox *) LDialogBox::CreateWindow(1000, this);
LStdButton *theButton;
theButton = (LStdButton*) aboutBox->FindPaneByID('ok ');
theButton->AddListener(this);
aboutBox->Show;
}
void AcereApp::ListenToMessage(MessageT inMessage, void *ioParam)
{
if (inMessage == pressedOK)
{
delete aboutBox;
}
}
// ---------------------------------------------------------------------------
// Ñ OpenDocument
// ---------------------------------------------------------------------------
// Open a Document file
void
AcereApp::OpenDocument(
FSSpec *inMacFSSpec)
{
CTextDoc *aDoc = new CTextDoc(this, inMacFSSpec);
}
// ---------------------------------------------------------------------------
// Ñ MakeNewDocument
// ---------------------------------------------------------------------------
// Create a new Document
LModelObject*
AcereApp::MakeNewDocument()
{
if (ourDoc == nil)
{
ourDoc = new CTextDoc(this, nil);
}
else
{
ourDoc->StartNewGame(false);
}
return ourDoc;
}
// ---------------------------------------------------------------------------
// Ñ ChooseDocument
// ---------------------------------------------------------------------------
// Prompt the user to select a document to open
void
AcereApp::ChooseDocument()
{
StandardFileReply macFileReply;
SFTypeList typeList;
UDesktop::Deactivate();
typeList[0] = 'TEXT';
::StandardGetFile(nil, 1, typeList, &macFileReply);
UDesktop::Activate();
if (macFileReply.sfGood) {
OpenDocument(&macFileReply.sfFile);
}
}